<?php

namespace App\Repositories;

class UserAuthRepository
{
    /**
     * 获取用户实名认证记录
     *
     * @param string $user_id
     *
     * @return array
     */
    public function getUserAuth($user_id)
    {
        return app('model_user_auth')->where(['user_id' => $user_id])->orderBy('id', 'desc')->first();
    }

    /**
     * 获取所有已经实名认证的用户
     * @return array
     */
    public function getAuthUsers()
    {
        return app('model_user_auth')->where(['app_status' => 1])->pluck('user_id')->flip()->toArray();
    }

    public function checkUserAuth($user_id)
    {
        $result = app('model_user_auth')->where(['user_id' => $user_id, 'app_status' => 1])->count();
        return $result > 0 ? 1 : 0;
    }
}
